<!--父级页面-->
<template>
  <!--侧边栏-->
  <div style="display: flex;">
    <!--是否折叠-->
    <div :style="{width:( isCollapse ? '82px': '190px')}">
      <!--菜单栏-->
      <el-menu
          background-color="#5B63B7"
          style="width:100%;height:100%;min-height:100vh;"
          text-color="#fff"
          active-text-color="#000"
          :collapse="isCollapse"
          :collapse-transition="false"
          @select="selectMenu"
          unique-opened router
      >
        <!--左侧菜单栏的顶部条-->
        <el-row style="padding-top: 10px;">
          <el-col :span="5">
          </el-col>
<!--          <el-col :span="7" style="padding-left:7px;">-->
<!--            <img src="/img/img.png" style="width:80px;height:50px;">-->
<!--          </el-col>-->
          <el-col :span="isCollapse ? 0 : 13">
            <img src="/img/img.png" style="width:100px;height:80px;">
<!--            <router-link to="/" style="color:#fff;text-decoration:none;position:relative;top:8px;left:2px;font-weight: bold;font-size: larger">-->
<!--              职来运转-->
<!--            </router-link>-->
          </el-col>
        </el-row>
        <!--菜单栏的导航项 -->
        <el-menu-item index="/index">
          <el-icon><House /></el-icon>
          <span>首页</span>
        </el-menu-item>
        <el-sub-menu index="1">
          <template #title>
            <el-icon style="font-size:21px;"><PieChart /></el-icon>
            <span>数据分析</span>
          </template>
          <el-menu-item index="/data">数据分析</el-menu-item>
          <el-menu-item index="/user">用户</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="2">
          <template #title>
            <el-icon style="font-size:21px;"><User /></el-icon>
            <span>应聘者管理</span>
          </template>
          <el-menu-item index="/seeker">应聘者信息</el-menu-item>
          <el-menu-item index="/note">简历信息</el-menu-item>
          <el-menu-item index="/submit">投递过程跟踪</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon style="font-size:21px;"><OfficeBuilding /></el-icon>
            <span>企业管理</span>
          </template>
          <el-menu-item index="/company">企业信息</el-menu-item>
          <el-menu-item index="/hr">招聘者信息</el-menu-item>
          <el-menu-item index="/employee">招聘信息</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="4">
          <template #title>
            <el-icon style="font-size:21px;"><ChatDotRound /></el-icon>
            <span>论坛管理</span>
          </template>
          <el-menu-item index="/content">论坛内容</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="5">
          <template #title>
            <el-icon style="font-size:21px;"><OfficeBuilding /></el-icon>
            <span>审批通知</span>
          </template>
          <el-menu-item index="/approvalCompany">企业入驻审批</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </div>
    <!--右侧主体部分-->
    <div :style="{width:( isCollapse ? 'calc(100% - 82px)': 'calc(100% - 190px)')}">
      <!--顶部菜单栏-->
      <el-header style="background-color:#fff;padding-top:10px;height:6vh">
        <el-icon style="font-size:20px;top:10px;float: left" @click="changeCollapsed"><Expand/></el-icon>
        <el-dropdown trigger="click" style="float: right;top: 8px">
                     <span style="font-size:19px;margin-right: 10px;margin-top: 3px">
                         admin
                    <!--<el-icon><arrow-down/></el-icon>下拉箭头-->
                     </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <div style="float: right;margin-right: 15px;margin-top: 12px"><el-icon size="large" color="#5B63B7"><UserFilled/></el-icon></div>
<!--        <span><el-avatar src="#" style="width:35px;height:35px;float: right;margin-top: 3px;margin-right: 10px"></el-avatar></span>-->
        <!--5.2 面包屑导航-->
        <el-breadcrumb separator="/" style="margin-top:15px;width: 50%;margin-left: 40px">
          <el-breadcrumb-item v-for="item in breadCrumb">{{item}}</el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>
      <!--6.右侧:主体内容是可变区域！-->
      <el-main style="padding:0;min-height:90vh;overflow-y: auto;">
        <router-view/>
      </el-main>
    </div>
  </div>
</template>

<script setup>
import {ref} from "vue";

//定义变量控制菜单是否折叠
const isCollapse = ref(false);
//修改折叠状态
const changeCollapsed = () => {
  isCollapse.value = !isCollapse.value;
}
//获取登录的用户信息
const user = ref(getUser());
//退出登录功能
const logout = () => {
  if(confirm('确定要退出吗？')){
    localStorage.removeItem('user');
    //退出时也需要将面包屑的值清空！
    localStorage.removeItem('breadcrumb');
    window.location.href = '/login';
    user.value = '';
  }
}
console.log(localStorage);
const breadCrumb = ref();
//定义数组维护不同页面的面包屑值
let map = {
  '/index':['首页'],
  '/data':['数据分析','数据分析'],
  '/user': ['数据分析','用户'],
  '/seeker': ['应聘者管理','应聘者信息'],
  '/note': ['应聘者管理','简历信息'],
  '/submit':['应聘者管理','投递过程跟踪'],
  '/company':['企业管理','企业信息'],
  '/hr':['企业管理','招聘者信息'],
  '/employee': ['企业管理','招聘信息'],
  '/content':['论坛管理','论坛内容'],
  '/approvalCompany':['审批通知','企业入驻审批']
}
//选择菜单项时触发
const selectMenu = (index) => {
  //根据选择的菜单项设置面包屑导航的值
  breadCrumb.value = map[index];
  //将值存入localStorage中,防止刷新页面时数据丢失
  localStorage.setItem('breadcrumb', JSON.stringify(breadCrumb.value));
};
</script>